let url="http://localhost:8080"
$.ajaxSetup({
    async:false,
})

//  --------------通过id和aid返回饭局信息    2020.2.3
function getActivitying(uid,aid) {
    let activitying = null
    $.post(url+"/ActivityServlet",{
        type:"getActivitying",
        id:uid,
        aid:aid
    }, function (data){
        activitying=data.data
    },"json")
    return activitying
}

//分割字符串,
function getcity(city) {
        let citys=[]
        citys=city.split(',')
        return citys
}

//  --------------通过id来返回用户信息
function login(uid) {
    let msg = null
    $.post(url+"/UserServlet",{
        type:"selectInfoById",
        id:uid
    }, function (data){
        msg=data.data
    },"json")
    return msg
}

// ----------------查询餐厅所有的类型
function getTypes(){
    let temp =null
    $.post(url+'/TypeServlet',{},function (typeResult,status) {
        if(status =="success"){
            temp = typeResult.data
        }else{
            alert('没获取到')
        }
    },"json")
    return temp
}

// ----------------获取当天日期
function newDate() {
    let date = new Date()
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    return y + '-' + m + '-' + d;
}


// -----------------------------------Sign_up -------------------------------------
// -----查询全部的饭局申请人
function selectAll(){
    let applyfanju=[]
    $.post(url+'/FanJuJoinServlet',{type:'selectAll'},function a(data) {
        applyfanju = data.data
    },"json")
    return applyfanju
}
// -----查询当前饭局的申请人数
function getCountByfanjuId(applyfanju,fanjuId){
    let people=0
    for(let i=0;i<applyfanju.length;i++){
        if(applyfanju[i].fanjuid==fanjuId){
            people++
        }
    }
    return people
}
// -----查询当前饭局的申请人是否有重复的
function isapplyFanju(applyfanju,userId,fanjuId){
    for(let i=0;i<applyfanju.length;i++){
        if(applyfanju[i].fanjuid==fanjuId && applyfanju[i].userid==userId){
           return false
        }
    }
    return true
}

// -----------------------------------Sucess.html -------------------------------------
// -----进入付款页面
function pay(applyfanju,userId,fanjuId){
    for(let i=0;i<applyfanju.length;i++){
        if(applyfanju[i].fanjuid==fanjuId && applyfanju[i].userid==userId){
            return false
        }
    }
    return true
}

// -----------------------------------Management.html -------------------------------------
// 获取某个饭局的所有申请人
function applyPeopleByFanJuId(applyfanju,fanjuId) {
    let applyUsers=[]
    let people=0
    alert('kaishi')
    for(let i=0;i<applyfanju.length;i++){
        if(applyfanju[i].fanjuid==fanjuId){
            people=people+parseInt(applyfanju[i].remarks2)
            // alert(people)
        }
    }
    return people
}

export default{
    login,
    getTypes,
    newDate,
    getcity,
    getActivitying,
    //---- Sign_up----
    selectAll,
    getCountByfanjuId,
    isapplyFanju,
    //---- Management.html----
    applyPeopleByFanJuId,
}